import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-04-12
 * Time: 17:41
 */
public class MyStack {
    public int[] elem;
    public int usedsize;

    public MyStack() {
        this.elem = new int[10];
    }

    public void push(int val){
        if(isFull()){
            this.elem = Arrays.copyOf(elem , elem.length * 2);
        }
        elem[usedsize++] = val;
    }

    private boolean isFull(){
        return usedsize == elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        int val = elem[usedsize - 1];
        usedsize--;
        return val;
    }

    public int peek(){
        if(isEmpty()){
            throw new EmptyStackException();
        }
        return elem[usedsize - 1];
    }

    private boolean isEmpty(){
        return usedsize == 0;
    }
}
